<template>
  <div class="data-top-wrapper">
    <xyDataHead @handleView="handleView">
      <template #icon>
        <svg-icon :icon-class="svgIcon" class="svg-icon"></svg-icon>
      </template>
      <template #title>
        <p>{{ title }}</p>
      </template>
      <template #view
        ><span @click="handleView"
          >详情<i class="el-icon-d-arrow-right right-icon"></i></span
      ></template>
    </xyDataHead>
    <div class="data-top-wrapper-container">
      <div v-for="(item, i) in listrArray" :key="i" class="data-top-item">
        <div style="display: flex; align-items: center">
          <div :class="getItemClass(item.value)">
            {{ item.value }}
          </div>
          <div class="data-top-item-name">
            {{ item.name }}
          </div>
        </div>
        <div class="data-top-item-num">{{ item.number }}</div>
      </div>
    </div>
  </div>
</template>
<script>
import xyDataHead from "./xy-data-head.vue";
export default {
  name: "DataTop",
  components: {
    xyDataHead,
  },
  props: {
    listrArray: {
      type: Array,
      default: () => [],
    },
    title: {
      type: String,
      default: "",
    },
    svgIcon: {
      type: String,
      default: () => "",
    },
  },
  data() {
    return {};
  },
  methods: {
    getItemClass(value) {
      const classMap = {
        1: "value1",
        2: "value2",
        3: "value3",
      };
      return classMap[value] || "value0";
    },
    handleView() {
      this.$emit("handleView");
    },
  },
};
</script>
<style scoped lang="scss">
.data-top-wrapper {
  width: 100%;
  height: 100%;
}
.data-top-wrapper-container {
  height: calc(100% - 50px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.data-top-item {
  height: 18%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  background-color: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
  transition: all 0.3s ease;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  .data-top-item-num {
    font-size: 0.9em;
    font-weight: 600;
  }
}
.data-top-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(59, 130, 246, 0.4);
  transform: translateX(4px);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
  .data-top-item-num {
    color: #60a5fa;
  }
}
.data-top-item:hover::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background: linear-gradient(to bottom, #3b82f6, #8b5cf6);
  transition: all 0.3s ease;
}
.data-top-item:hover:before {
  transform: scaleY(1);
}
.data-top-item-name {
  font-size: 0.8em;
}
.value1,
.value2,
.value3,
.value0 {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  margin-right: 8px;
}
.value1 {
  background: linear-gradient(135deg, #fa9f02, #f9b509);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
}
.value2 {
  background: linear-gradient(135deg, #6b7280, #9ca3af);
  box-shadow: 0 0 8px rgba(107, 114, 128, 0.3);
}
.value3 {
  background: linear-gradient(135deg, #b45309, #d97706);
  box-shadow: 0 0 8px rgba(180, 83, 9, 0.3);
}
.value0 {
  background: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
  box-shadow: 0 0 8px rgba(30, 64, 175, 0.3);
}
.right-icon {
  animation: float 1s ease-in-out infinite;
}

@keyframes float {
  0%,
  100% {
    transform: translateX(0);
  }
  50% {
    transform: translateX(3px);
  }
}
</style>
